;;; dev-setup.el --- Customize Emacs for special projects

;; Copyright (C) 2010  Markus

;; Author: Markus <markus.prepens@googlemail.com>
;; Keywords: tools, c

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Two version might help you to get things like code completion and call tree
;; navigation.
;;
;; One version uses Cscope and auto-complete mode. auto-complete mode is hosted
;; on http://cx4a.org/software/auto-complete.
;;
;; And a second version `my-dev-setup-evo' uses Cedet. The Cedet version
;; uses Cscope or, if Cscope DB is not present, grep as backend. Please note,
;; that the grep backend is way too slow.
;;
;; TODO: Because the second version uses a simple EDE project framework, some
;; specific search paths are configured in `my-dev-setup-evo'. A more
;; generic approach has to be found. `my-dev-setup-gnu' try to solve it.
;;

;;; Code:



(defun my-dev-setup-cscope-with-auto-complete (desk-dir)
  "Project support, based on Cscope. To build a Cscope data base,
first create a file 'cscope.files' that containes all files to be
parsed. To create the database itself, do a 'cscope -bk'. That's
it!"
  (interactive "DDesktop directory:")
  (add-to-list 'load-path "~/.emacs.d/modes/auto-complete")
  (require 'auto-complete-config)
  (require 'xcscope)
  (add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
  (ac-config-default)
  (setq ac-auto-show-menu nil
        ac-auto-start nil
        ac-ignore-case nil
        ac-trigger-commands nil
        ac-trigger-key "TAB")
  (cscope-set-initial-directory desk-dir)
  (desktop-change-dir desk-dir))


(defun my-dev-setup-evo (desk-dir)
  "Adds specific support for EVO projects, based on Cedet. To set
a proper locate tool, customize `ede-locate-setup-options'.

This function needs further testing: ede-cpp-root-project did not
work as expeced. Header file search with :system-include-path did
not work. The workaround: Use semantic-add-system-include instead
of :system-include-path."
  (interactive "DDesktop directory:")
  (require 'cedet)
  (require 'semantic)
  (require 'ede)
  (global-ede-mode t)

  (ede-cpp-root-project "EVO"
                        :file (concat desk-dir "cscope.files"))
  (setq ede-auto-add-method 'always)
  (semantic-mode t)
  (setq semantic-default-submodes '(global-semantic-highlight-func-mode
                                    global-semantic-stickyfunc-mode
                                    global-semantic-idle-scheduler-mode
                                    global-semanticdb-minor-mode
                                    global-semantic-mru-bookmark-mode))
  (add-hook 'c-mode-hook
            (lambda ()
              (local-set-key (kbd "C-<return>") 'semantic-complete-inline-done)
              (local-set-key (kbd "C-c , <tab>") 'semantic-analyze-proto-impl-toggle)
              (semantic-add-system-include (concat desktop-dirname "/HeaterCore"))
              (semantic-add-system-include (concat desktop-dirname "/Application"))))
  (desktop-change-dir desk-dir))

(defun my-dev-root(dir)
  desktop-dirname)

(defun my-test-setup-evo (desk-dir)
  (interactive "DDesktop directory:")
  (require 'cedet)
  (require 'semantic)
  (semantic-mode t)
  (setq semantic-default-submodes (quote (global-semantic-highlight-func-mode
                                          global-semantic-stickyfunc-mode
                                          global-semantic-idle-scheduler-mode
                                          global-semanticdb-minor-mode
                                          global-semantic-mru-bookmark-mode)))
  (add-hook 'c-mode-hook
            (lambda ()
              (local-set-key (kbd "C-c , <tab>") 'semantic-analyze-proto-impl-toggle)
              (semantic-add-system-include (concat desktop-dirname "/HeaterCore"))
              (semantic-add-system-include (concat desktop-dirname "/Application"))))
  (setq semanticdb-project-root-functions 'my-dev-root)
  (setq semanticdb-project-root-functions 'my-dev-root)
  (desktop-change-dir desk-dir))


(defun my-dev-setup-gnu (desk-dir)
  "Adds specific support for GNU projects, based on Cedet. To set
a proper locate tool, customize `ede-locate-setup-options'.

This function needs further testing: ede-cpp-root-project did not
work as expeced. Header file search with :system-include-path did
not work. The workaround: Use semantic-add-system-include instead
of :system-include-path."
  (interactive "DDesktop directory:")
  (require 'cedet)
  (require 'semantic)
  (require 'ede)
  (global-ede-mode t)
  (ede-cpp-root-project "EVO"
                        :file (concat desk-dir "/cscope.files"))
  (setq ede-auto-add-method 'always)
  (semantic-mode t)

  (setq semantic-default-submodes (quote (global-semantic-highlight-func-mode
                                          global-semantic-stickyfunc-mode
                                          global-semantic-idle-scheduler-mode
                                          global-semanticdb-minor-mode
                                          global-semantic-mru-bookmark-mode)))
  (desktop-change-dir desk-dir))



(provide 'resource/dev-setup)
;;; dev-setup.el ends here
